fix(js): make _acf-compatibility.js strict-mode safe#511
Open
faisalahammad wants to merge 1 commit into
Open
Conversation
- Declare local `keys` in maybe_get() — was an implicit global that throws ReferenceError under strict mode - Replace `arguments`-forwarding recursion in add_action() multi-action split with explicit positional args — strict mode disables `arguments` aliasing of named parameters - Add static regression tests that fail if either pattern returns Fixes WordPress#460
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The legacy compatibility layer in
assets/src/js/_acf-compatibility.jsrelied on sloppy-mode (non-strict) JavaScript semantics. Two patterns break the moment the module is forced into strict mode (e.g. via an ES module conversion or a bundler default change):maybe_get()assigned to an undeclaredkeysvariable — a global leak that becomes aReferenceErrorunder strict mode.add_action()'s multi-action split used_acf.add_action.apply(this, arguments)to forward the namedactionparameter — strict mode disablesargumentsaliasing of named parameters, so the recursive call silently stopped wrapping user callbacks.Both spots are fixed without behavior change. Static regression tests added under
strict-mode safety (regression for #460)intests/js/compatibility.test.jsfail loudly if either pattern returns.Verification:
npm run test:unit— 953/953 passnpm run test:unit -- tests/js/compatibility.test.js— 28/28 pass including 2 new strict-mode testscoderabbit review --agent— 0 findingsvaraddition and the removedaction = actions[i]reassignment)Closes #460
Use of AI Tools
Portions of this PR were authored with the assistance of AI tooling. All changes have been reviewed, tested, and verified by a human contributor.